var mysql = require('mysql');

var TEST_DATABASE = 'bee_test';
var TEST_TABLE = 'node_user';

// var client = mysql.createConnection({
    // host: '127.0.0.1',
    // port: '3306',
    // user: 'root',
    // password: 'root',
    // database: TEST_DATABASE,
// });
var client = mysql.createConnection({
    host: '123.207.1.188',
    port: '3306',
    user: 'root',
    password: 'T!3=G:4w}oV]KK}',
    database: TEST_DATABASE,
});

client.connect();

// 插入
var sql = 'INSERT INTO node_user(id, title, password) VALUES(0, ?, ?)';
var params = ['beephp', 'beephp'];

client.query(sql, params, function (err, result) {
	if ( err ) {
		console.log('[INSERT ERROR] - ', err.message);
		return;
	}

	console.log('-------INSERT----------');
	console.log('result:', result);
	console.log('#######################');
});

// 更新
var sql = 'UPDATE node_user SET title = ?, password = ? WHERE id = ?';
var params = ['BeeCsharp', 'BeeCsharp', 3];

client.query(sql, params, function (err, result) {
	if ( err ) {
		console.log('[UPDATE ERROR] - ', err.message);
		return;
	}

	console.log('----------UPDATE-------------');
	console.log('result', result);
	console.log('#######################');
});

// 查询
var sql = 'SELECT * FROM node_user';

client.query(sql, function (err, result) {
	if ( err ) {
		console.log('[SELECT ERROR] - ', err.message);
		return;
	}

	console.log('---------------SELECT----------------');
	console.log('SELECT', result);
	console.log('#######################');
});

// 删除
var  sql = 'DELETE FROM node_user WHERE id = 4';

client.query(sql, function (err, result) {
	if ( err ) {
		console.log('[DELETE ERROR] - ', err.message);
		return;
	}

	console.log('-------------DELETE--------------');
	console.log('DELETE', result);
	console.log('#######################');
});

client.end();
